package July;

import June03.Employee;
import June03.Student;

import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import static javax.swing.WindowConstants.EXIT_ON_CLOSE;

public class Test01Arraycopy {
    public static void main(String[] args) {
        Student stu = new Student("zhangsan", "男", 18);
        Student stu2 = new Student("zhangsan1", "男", 18);
        Student stu3 = new Student("zhangsan2", "男", 18);
        Student[] arr1 = {stu, stu2, stu3};

        Employee[] arr2 = new Employee[3];

        System.arraycopy(arr1, 0, arr2, 0, 3);

        for (int i = 0; i < arr2.length; i++) {
//            Student stu4= (Student) arr2[i];
//            System.out.println(stu4.getName()+" ,"+stu4.getAge());
            System.out.println(arr2[i].getName() + " ," + arr2[i].getAge());
        }
        JFrame jFrame = new JFrame();
        JButton but = new JButton("退出");
        JButton but2 = new JButton("显示线程数");

        jFrame.setTitle("窗口");
        //设置窗口图标
        ImageIcon img = new ImageIcon("E:\\idea project\\PuzzleGame\\image\\logo.png");
        jFrame.setIconImage(img.getImage());
        //设置窗口大小
        jFrame.setBounds(0, 0, 400, 300);
        //居中
        jFrame.setLocationRelativeTo(null);
        //关闭模式
        jFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);

        //为窗口添加JPanel布局
        JPanel jPanel = new JPanel();
        jPanel.setLayout(null);
        jFrame.setContentPane(jPanel);
        but.setBounds(0, 0, 80, 40);
        but2.setBounds(80, 0, 80, 40);
        jPanel.add(but);
        jPanel.add(but2);
        but2.setVisible(false);

        but.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                but.setVisible(false);
                but2.setVisible(true);
                new ShowJDialog().showJDialog(jFrame,"抽象",200,100,true,null);

            }
        });

        but2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //获取到线程数
                int xc = Runtime.getRuntime().availableProcessors();
                //创建一个弹窗对象
                JDialog jDialog = new JDialog();
                jDialog.setTitle("显示线程数");
                jDialog.setLayout(null);
                jDialog.setSize(400, 200);
                //居中
                jDialog.setLocationRelativeTo(null);
                //创建一个文本
                JLabel jLabel = new JLabel(String.valueOf(xc));
                jLabel.setBorder(new BevelBorder(0));
                jLabel.setBounds(0, 0, 100, 50);
                //将标签jlabel加入到jdialog
                jDialog.add(jLabel);
                //显示弹窗
                jDialog.setVisible(true);
                JButton but3 = new JButton("设置1h后关机");
                but3.setBounds(100, 100, 100, 50);
                jDialog.add(but3);
                but3.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            //shutdown -s -t 18000的聪cmd代码是设置60分钟后自动关机
                            Runtime.getRuntime().exec("shutdown -a");
                        } catch (IOException ex) {
                            throw new RuntimeException(ex);
                        }
                    }
                });

            }
        });
        jFrame.setVisible(true);


    }
}
